package org.ls.petclinic.dao.impl;

import org.ls.petclinic.dao.PetsDao;
import org.ls.petclinic.pojo.Pets;

import java.util.List;

/**
 * @author 浪矢先生
 * @description
 * @create 2022-12-05 21:56
 */
public class PetsDaoImpl extends BaseDao implements PetsDao {
    @Override
    public List<Pets> getAll() {
        return queryForList(Pets.class, "select * from pets");
    }

    @Override
    public List<Pets> getByName(String name) {
        return queryForList(Pets.class,"select * from pets where name like ?","%"+name+"%");
    }

    @Override
    public List<Pets> getByOwnerId(Long ownerId) {

        return queryForList(Pets.class,"select * from pets where ownerId=?",ownerId);
    }

    @Override
    public int add(Pets pets) {
        return update("insert into pets(name,birthDate,ownerId,typeId) values(?,?,?,?)",pets.getName(),pets.getBirthDate(),pets.getOwnerId(),pets.getTypeId());
    }

    @Override
    public Pets getById(Long id) {

        return  queryForOne(Pets.class, "select * from pets where id =?", id);
    }
}
